/*
 * Portfolio.cpp
 *
 *  Created on: Sep 30, 2009
 *      Author: karthik
 */
#include "Portfolio.h"

#include<iostream>
#include<vector>

using namespace std;

double Portfolio::getvalue(double spot, double volatility, Date date, vector<double>& stock_values){
	/*
	 * Returns sum of values of all options in the portfolio.
	 */

	double value1=0,value2=0;
	int len = optionsBought.size();
	double rate=0.02;
//	cout<<"len "<<len<<endl;
	for(int i=0;i<len;i++){
		Option opt = optionsBought.at(i);
		value1 += opt.call_price(spot,rate,volatility,date);
	}
//	cout<<"Bought options value : "<<value1<<endl;
	stock_values.push_back(value1);

	len = optionsSold.size();
//	cout<<"len "<<len<<endl;
	for(int i=0;i<len;i++){
		Option opt = optionsSold.at(i);
		value2 += opt.call_price(spot,rate,volatility,date);
	}
//	cout<<"Sold options value : "<<value2<<endl;
	stock_values.push_back(value2);
	return value1-value2;

}

void Portfolio::addOption(Option opt, bool isBought){
//	std::cout<<"Adding Option to"<< isBought <<std::endl;
	isBought?optionsBought.push_back(opt):optionsSold.push_back(opt);
	/*
	if (isBought){
		optionsBought.push_back(opt);
	}else{
		optionsSold.push_back(opt);
	}
	*/
}
